import {
  Controller,
  Get,
  UseGuards,
  Req,
  Param,
  Post,
  Body,
  Delete,
  Patch,
} from "@nestjs/common";
import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard";
import { UserService } from "../user/user.service";
import { RespWrap } from "src/common/base.utils";
import { UpdateUserDto } from "./dto/update.user.dto";
import { CreateUserDto } from "./dto/create.user.dto";

@UseGuards(JwtAuthGuard)
@Controller("users")
export class UserController {
  constructor(private userService: UserService) {}

  @Get()
  async pageQuery(@Req() req) {
    const resp = await this.userService.pageQuery({
      ...req.query,
    });
    return RespWrap(resp);
  }

  @Post()
  async insert(@Body() body: CreateUserDto) {
    const resp = await this.userService.insert(body);
    return RespWrap(resp);
  }

  @Delete(":id")
  async removeById(@Param() params) {
    const resp = await this.userService.removeById(params.id);
    return RespWrap(resp);
  }

  @Patch(":id")
  async update(@Param() params, @Body() body: UpdateUserDto) {
    const resp = await this.userService.update({
      id: params.id,
      ...body,
    });
    return RespWrap(resp);
  }
}
